package main

import (
	_ "dzomc/controllers"
	_ "dzomc/routers"
	"dzomc/tcp"
	"log"
	"time"

	"github.com/astaxie/beego/orm"

	// "dzomc/models"

	"github.com/astaxie/beego"
	_ "github.com/mattn/go-sqlite3"
)

//在此处初始化完成，才不会报nil错误
//应该有其它的方法，比如先后启动？？，参数传递？？
var TcpServer *(tcp.AsyncTCPServer) = tcp.NewAsyncTCPServer("localhost:9001", &EchoCallback{}, &LoraProtocol{})

func init() {
	orm.RegisterDriver("sqlite3", orm.DRSqlite)

	orm.RegisterDataBase("default", "sqlite3", "lora.db3")

	orm.RunSyncdb("default", false, true) //第一个true
	orm.DefaultTimeLoc = time.UTC
}

func main() {

	//TcpServer := tcp.NewAsyncTCPServer("localhost:9001", &EchoCallback{}, &EchoProtocol{})
	log.Println("tcpserver:", TcpServer)
	TcpServer.SetReadDeadline(time.Second * 1000)
	log.Println("tcp server start...")
	TcpServer.ListenAndServe()
	log.Println("http server start...")
	beego.BConfig.WebConfig.Session.SessionOn = true  //使能session
	beego.BConfig.Log.AccessLogs = false
	beego.SetLevel(beego.LevelError)
	beego.Run()
}
